package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.SchoolManagementService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @描述 运营管理平台
 * @创建人 zm
 * @创建时间 2020/5/4
 */
@RestController
@RequestMapping("/admin")
public class SchoolManagementController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SchoolManagementService service;

    /**
     * @描述 根据权限查询数据
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/queryPersonDataByRole")
    public Result queryPersonDataByRole(RequestParameterWrapper request) {
        String role = request.getParam("role");
        logger.info("SchoolManagementController --> queryPersonDataByRole,role={}", role);
        return service.queryPersonDataByRole(Integer.parseInt(role));
    }

    /**
     * @描述 运营人员添加修改数据/添加
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/addPersonData")
    public Result addPersonData(@RequestParam(value = "id", required = false) Integer id,
                                @RequestParam(value = "head_portrait", required = false) String head_portrait,
                                @RequestParam(value = "admin_name", required = false) String admin_name,
                                @RequestParam(value = "phone") String phone,
                                @RequestParam(value = "password") String password) {
        return service.addPersonData(id, head_portrait, admin_name, phone, password);
    }

    /**
     * @描述 根据id查个人信息
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/queryPersonDataById")
    public Result queryPersonDataById(@RequestParam(value = "id") Integer id) {
        return service.queryPersonDataById(id);
    }

    /**
     * @描述 添加/修改代理商信息
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/addAgentData")
    public Result addAgentData(@RequestParam(value = "id", required = false) Integer id,
                               @RequestParam(value = "head_portrait", required = false) String head_portrait,
                               @RequestParam(value = "corporate_name", required = false) String corporate_name,
                               @RequestParam(value = "address", required = false) String address,
                               @RequestParam(value = "phone") String phone,
                               @RequestParam(value = "password") String password,
                               @RequestParam(value = "admin_name", required = false) String admin_name) {
        return service.addAgentData(id, head_portrait, corporate_name, address, phone, password,admin_name);
    }

    /**
     * @描述 删除人员信息
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/delPersonData")
    public Result delPersonData(@RequestParam(value = "id") Integer id) {
        return service.delPersonData(id);
    }


    /**
     * @描述 查所有的省->市->区
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/queryDistrict")
    public Result queryDistrict(@RequestParam(value = "id", required = false) Integer id,
                                @RequestParam(value = "type", required = false) Integer type) {
        return service.queryDistrict(id, type);
    }

    /**
     * @描述 查所有的学校
     * @创建人 zm
     * @创建时间 2020/5/4
     */
    @RequestMapping("/querySchoolAll")
    public Result querySchoolAll(RequestParameterWrapper request,
                                 @RequestParam(value = "name", required = false) String name,
                                 @RequestParam(value = "corporateName", required = false) String corporateName,
                                 @RequestParam(value = "id", required = false) Integer id,
                                 @RequestParam(value = "type", required = false) Integer type,
                                 @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                 @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        String adminId = request.getParam("adminId");
        String role = request.getParam("role");
        return service.querySchoolAll(name, id, type, indexNo, rows, adminId, role,corporateName );
    }

    /**
     * @描述 修改学校信息
     * @创建人 zm
     * @创建时间 2020/5/5
     */
    @RequestMapping("/updateSchoolDate")
    public Result updateSchoolDate(@RequestParam(value = "sid") Integer sid,//学校id
                                   @RequestParam(value = "sname", required = false) String sname,//学校名字
                                   @RequestParam(value = "logo", required = false) String logo,
                                   @RequestParam(value = "districtId") Integer districtId,//地区id
                                   @RequestParam(value = "tid", required = false) Integer tid,//教师id
                                   @RequestParam(value = "tname", required = false) String tname,//教师名字
                                   @RequestParam(value = "phone") String phone,//电话
                                   @RequestParam(value = "password") String password,//密码
                                   @RequestParam(value = "endtime", required = false) String endtime,//失效时间
                                   @RequestParam(value = "sbnumber") Integer sbnumber,
                                   @RequestParam(value = "type") Integer type,
                                   @RequestParam(value = "areaPlatformId",required = false) Integer areaPlatformId,
                                   @RequestParam(value = "jingWeiDu",required = false) Integer jingWeiDu) {//设备数量
        return service.updateSchoolDate(sid, sname, logo, districtId, tid, tname, phone, password, endtime, sbnumber, type,areaPlatformId,jingWeiDu);
    }


    /**
     * @描述 添加学校信息
     * @创建人 zm
     * @创建时间 2020/5/5
     */
    @RequestMapping("/addSchoolDate")
    public Result addSchoolDate(RequestParameterWrapper request,
                                @RequestParam(value = "sname", required = false) String sname,
                                @RequestParam(value = "logo", required = false) String logo,
                                @RequestParam(value = "districtId") Integer districtId,
                                @RequestParam(value = "tname", required = false) String tname,
                                @RequestParam(value = "phone") String phone,
                                @RequestParam(value = "password") String password,
                                @RequestParam(value = "endtime", required = false) String endtime,
                                @RequestParam(value = "sbnumber") Integer sbnumber,
                                @RequestParam(value = "type") Integer type,
                                @RequestParam(value = "areaPlatformId",required = false) Integer areaPlatformId,
                                @RequestParam(value = "jingWeiDu",required = false) Integer jingWeiDu ) {
        String adminId = request.getParam("adminId");
        return service.addSchoolDate(sname, logo, districtId, tname, phone, password, endtime, sbnumber, adminId, type,areaPlatformId,jingWeiDu);
    }

    /**
     * @描述 根据id查学校信息
     * @创建人 zm
     * @创建时间 2020/5/5
     */
    @RequestMapping("/querySchoolDateById")
    public Result querySchoolDateById(@RequestParam(value = "id") Integer id) {
        return service.querySchoolDateById(id);
    }

    /**
     * @描述 根据学校id 删除学校信息
     * @创建人 zm
     * @创建时间 2020/5/14
     */
    @RequestMapping("/delSchoolDateById")
    public Result delSchoolDateById(@RequestParam(value = "id") Integer id) {
        return service.delSchoolDateById(id);
    }

    /**
     * @描述 查询该学校功能权限
     * @创建人 zm
     * @创建时间 2020/5/6
     */
    @RequestMapping("/querySchoolManagementJurisdiction")
    public Result querySchoolManagementJurisdiction(@RequestParam(value = "id") Integer id) {
        return service.querySchoolManagementJurisdiction(id);
    }

    /**
     * @描述 添加菜单权限
     * @创建人 zm
     * @创建时间 2020/5/6
     */
    @RequestMapping("/addSchoolManagementJurisdiction")
    public Result addSchoolManagementJurisdiction(@RequestParam(value = "menuOne", required = false) String menuOne, @RequestParam(value = "menuTwo", required = false) String menuTwo, @RequestParam(value = "id") Integer id) {
        logger.info("addschoolManagementJurisdiction-->menuOne={},menuTwo={},shool_id={}", menuOne, menuTwo, id);
        return service.addSchoolManagementJurisdiction(menuOne, menuTwo, id);
    }

    /**
     * @描述 添加学期
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/addSchoolSemester")
    public Result addSchoolSemester(@RequestParam(value = "name") String name,
                                    @RequestParam(value = "schoolId") Integer schoolId,
                                    @RequestParam(value = "oneTerm") String oneTerm,
                                    @RequestParam(value = "oneTime") String oneTime,
                                    @RequestParam(value = "twoTerm") String twoTerm,
                                    @RequestParam(value = "twoTime") String twoTime) {
        return service.addSchoolSemester(name, schoolId, oneTerm, oneTime, twoTerm, twoTime);
    }

    /**
     * @描述 修改学年信息
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/updateSchoolSemester")
    public Result updateSchoolSemester(@RequestParam(value = "id") Integer id,
                                       @RequestParam(value = "name") String name,
                                       @RequestParam(value = "schoolId") Integer schoolId,
                                       @RequestParam(value = "oneTerm") String oneTerm,
                                       @RequestParam(value = "oneTime") String oneTime,
                                       @RequestParam(value = "twoTerm") String twoTerm,
                                       @RequestParam(value = "twoTime") String twoTime) {
        return service.updateSchoolSemester(id, name, schoolId, oneTerm, oneTime, twoTerm, twoTime);
    }


    /**
     * @描述 设置为当前学年
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/updateSemesterState")
    public Result updateSemesterState(@RequestParam(value = "id") Integer id,
                                      @RequestParam(value = "schoolId") Integer schoolId) {
        return service.updateSemesterState(id, schoolId);
    }

    /**
     * @描述 根据id查学年信息
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/querySemesterById")
    public Result querySemesterById(@RequestParam(value = "id") Integer id) {
        return service.querySemesterById(id);
    }

    /**
     * @描述 根据学校id查学年信息
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/querySemesterBySchoolId")
    public Result querySemesterBySchoolId(@RequestParam(value = "schoolId") Integer schoolId) {
        return service.querySemesterBySchoolId(schoolId);
    }

    /**
     * @描述 组合查询学校学年
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/querySemesterSchoolList")
    public Result querySemesterSchoolList(@RequestParam(value = "name", required = false) String name,
                                          @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                          @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        return service.querySemesterSchoolList(name, indexNo, rows);
    }

    /**
     * @描述 升学年
     * @创建人 zm
     * @创建时间 2020/5/8
     */
    @RequestMapping("/updateSchoolUpgrade")
    public Result updateSchoolUpgrade(@RequestParam(value = "schoolId") Integer schoolId, @RequestParam(value = "id") Integer id) {//学年id
        return service.updateSchoolUpgrade(schoolId, id);
    }

    /**
     * @描述 查学年id
     * @创建人 zm
     * @创建时间 2020/5/16
     */
    @RequestMapping("/querySemesterYearId")
    public Result querySemesterYearId(@RequestParam(value = "schoolId") Integer schoolId) {
        return service.querySemesterYearId(schoolId);
    }


    @PostMapping("/adminUpload")
    public Result upload(@RequestPart("file") MultipartFile file, @RequestParam("type") int type) {

        logger.info("上传文件/图片/人脸");

        return service.upload("0", file, type);
    }

    /**
     * @描述 修改管理者密码
     * @创建人 zm
     * @创建时间 2020/5/5
     */
    @RequestMapping("/updateSchoolAdminPassword")
    public Result updateSchoolAdminPassword(@RequestParam(value = "id") Integer id,@RequestParam(value = "password") String password) {
        logger.info("修改管理者密码");
        return service.updateSchoolAdminPassword(id,password);
    }

    /**
     *查询未登录信息
     * @param sid
     * @return
     */
    @RequestMapping("/findNotLoggedIn")
    public void findNotLoggedIn(RequestParameterWrapper request,
                                HttpServletResponse response,
                                @RequestParam("sid") Integer sid) {

        logger.info("查询未登录信息");

         service.findNotLoggedIn(request,response,sid);
    }


    /**
     * @Author zm
     * @Description 删除人脸数据推送
     * @Date 2020/10/20 15:21
     */
    @RequestMapping("/delFaceDataByClassId")
    public Result delFaceDataByClassId(@RequestParam(value = "classIds") String classIds) {
        logger.info("删除人脸数据推送");
        return service.delFaceDataByClassId(classIds);
    }

    /**
     * @Author zm
     * @Description 查询班级接口
     * @Date 2020/10/20 16:55
     */
    @RequestMapping("/queryClassList")
    public Result queryClassList(@RequestParam(value = "schoolId") Integer schoolId) {
       return service.queryClassList(schoolId);
    }
}
